<?php

// $Id$

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/menu/tcms_menu_item_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/vpage/tcms_vpt_menu_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/vpage/tcms_vpage_dbc.class.php');


class TCMS_Menu_Item_Deleter extends Tangra_Class {
	public static function delete(DB_Connection $dbc, $id, $hidden_inc_dir, $user_id) {
		tangra_if_not_int_throw_e($id);
		tangra_if_not_int_throw_e($user_id);

		$sql = "select vpages.id ".
					"from tcms_menu_items mi, ".
							"tcms_menus m, ".
							"tcms_vpt_menus vptm, ".
							"tcms_vpages vpages ".
						"where mi.id = $id and ".
							"mi.menu = m.id and ".
							"m.id = vptm.menu and ".
							"vpages.template = vptm.template";
		$rez = $dbc->execute($sql);
		while ($rez_obj = $rez->fetch_object()) {
			TCMS_VPage_DBC::update_last_modified($dbc, $rez_obj->ID, $user_id);
		}


		TCMS_Menu_Item_DBC::delete_cascade($dbc, $id, $hidden_inc_dir);
	}
}